package com.atguigu.chapter11;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.catalog.hive.HiveCatalog;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/7/24 16:25
 */
public class Flink14_Hive {
    public static void main(String[] args) {
        System.setProperty("HADOOP_USER_NAME", "atguigu");
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
    
        StreamTableEnvironment tenv = StreamTableEnvironment.create(env);
    
        // 创建hive的catalog
        HiveCatalog hive = new HiveCatalog("hive", "gmall", "input/");
        // 注册catalog
        tenv.registerCatalog("hive", hive);
        tenv.useCatalog("hive"); //设置默认的catalog
        tenv.useDatabase("gmall");
        
//        tenv.sqlQuery("select * from hive.gmall.person").execute().print();
        tenv.sqlQuery("select * from person").execute().print();
        
    }
}
